package com.jl15988.chainlog.example;

import com.jl15988.chainlog.annotation.ChainApi;
import com.jl15988.chainlog.annotation.ChainController;
import com.jl15988.chainlog.annotation.ChainCustom;
import com.jl15988.chainlog.annotation.ChainDisabled;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 示例控制器
 */
@RestController
@RequestMapping("/api/example")
@ChainController(module = "用户管理")
public class ExampleController {

    @Autowired
    private ExampleService exampleService;

    /**
     * 全局监控示例（当配置为GLOBAL模式时自动监控）
     */
    @GetMapping("/global")
    public String globalMonitor(@RequestParam String name) throws InterruptedException {
        return exampleService.processData(name);
    }

    /**
     * 注解监控示例
     */
    @ChainApi(
            name = "用户查询",
            operationType = "QUERY",
            customs = {
                    @ChainCustom(key = "user", value = "zhangsan")
            }
    )
    @PostMapping("/annotation")
    public String annotationMonitor(@RequestBody ExampleRequest request) {
        return exampleService.processComplexData(request.getData());
    }

    /**
     * 不监控示例
     */
    @ChainDisabled(reason = "健康检查接口，无需监控")
    @GetMapping("/health")
    public String health() {
        return "OK";
    }

    /**
     * 自定义监控参数示例
     */
    @ChainApi(
            module = "订单管理",
            name = "订单创建",
            operationType = "CREATE"
    )
    @PostMapping("/order")
    public String createOrder(@RequestBody ExampleRequest request) {
        return exampleService.createOrder(request.getData());
    }
}